/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managerBeanViews;

import entity.Articles;
import entity.Category;
import entity.Complaint;
import entity.Department;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import processor.ArticlesFacade;
import processor.CategoryFacade;
import processor.ComplaintFacade;
import processor.DepartmentFacade;

/**
 *
 * @author maynoigi
 */
@ManagedBean
@SessionScoped
public class Index implements Serializable{

    @EJB
    private ComplaintFacade complaintFacade;
    @EJB
    private ArticlesFacade articlesFacade;
    @EJB
    private DepartmentFacade departmentFacade;
    @EJB
    private CategoryFacade categoryFacade;
    private List<Category> categorys;
    private List<Department> departments;
    private List<Articles> articles;
    private List<Complaint> complaint;
    private String titlePage = "Complaints News";

    public String getTitlePage() {
        return titlePage;
    }

    public void setTitlePage(String titlePage) {
        this.titlePage = titlePage;
    }

    public int getFlag() {
        return flag;
    }

    public void setFlag(int flag) {
        this.flag = flag;
    }
    int flag = 0;

    public Index() {
    }

    public List<Complaint> getComplaint() {
        if (flag == 0) {
            complaint = complaintFacade.getComplaintAll();
        }
        return complaint;
    }

    public void setComplaint(List<Complaint> complaint) {
        this.complaint = complaint;
    }

    public String getTitle() {
        title = "Complaints New";
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }
    private String title;

    public List<Category> getCategorys() {
        categorys = categoryFacade.getCategoryAll();
        return categorys;
    }

    public void setCategorys(List<Category> categorys) {
        this.categorys = categorys;
    }

    public List<Department> getDepartments() {
        departments = departmentFacade.getDepartmentAll();
        return departments;
    }

    public void setDepartments(List<Department> departments) {
        this.departments = departments;
    }

    public List<Articles> getArticles() {
        articles = articlesFacade.getArticlesByCount(5);
        return articles;
    }

    public void setArticles(List<Articles> articles) {
        this.articles = articles;
    }

    public String complaintByCategory(Category iD) {
        complaint = complaintFacade.getComplaintByCategory(iD);
        flag = 1;
        titlePage = "Complaints About " + iD.getCategoryName();
        return "index.xhtml";
    }

    public String home() {
        flag = 0;
        titlePage = "Complaints News";
        return "index.xhtml";
    }

    public String complaintByDepartments(Department iD) {
        complaint = complaintFacade.getComplaintByDepartments(iD);
        flag = 1;
        titlePage = "Complaints In " + iD.getDepartmentName()+" Department";
        return "index.xhtml";
    }
}
